package com.kaifamiao.demo.d0726;

public class Demo {

    public int sum(int a, int b){
        return a + b;
    }

    public static void main(String[] args) {
        Demo demo = new Demo();
//        int sum = 0;
//        for(int i = 1; i <= 10; i ++){
//            sum = demo.sum(sum, i);
//        }
//        System.out.println(sum);

//        int n = demo.jc2(5);
        int n = demo.sum(100);
        System.out.println(n);
    }

    public int sum(int num){
        if (num == 1){
            return 1;
        }
        return num + sum(num - 1);
    }


    /*
        递归： 自己调用自己
            要有出口（终止条件）
         5! = 5 * 4!   5 * 24 = 120
         4! = 4 * 3!   4 * 6 = 24
         3! = 3 * 2!   3 * 2 = 6
         2! = 2 * 1!   2 * 1 = 2
         1! = 1
     */
    public int jc2(int num){
        // 递归的出口
        if (num == 1){
            return 1;
        }
        return num * jc2(num - 1);
    }

    public int jc(int num){
        int n = 1;
        for (int i = 1; i <= num; i ++){
            n = n * i;
        }
        return n;
    }


}
